public class Test1 {
//    public static void main(String[] args) {
////        MyArray myArray = new MyArray();
////        myArray.setVal(0, 10);
////        myArray.setVal(1, "hello");//字符串也可以存放
////        String ret = (String) myArray.getPos(1);//编译报错
////        System.out.println(ret);
//    }
    
    public static void main(String[] args) {
        MyArray<Integer> myArray1 = new MyArray<>();
        myArray1.setVal(0,10);
        myArray1.setVal(1,12);
        
        MyArray<String> myArray2 = new MyArray<>();
        myArray2.setVal(0,"hello");
        myArray2.setVal(1,"world");
        
        MyArray<Float> myArray3 = new MyArray<>();
        myArray3.setVal(0,1.23f);
        myArray3.setVal(1,3.14f);
    }
    
}

//class MyArray {
//    public Object[] array = new Object[10];
//    public Object getPos(int pos) {
//        return this.array[pos];
//    }
//    public void setVal(int pos,Object val) {
//        this.array[pos] = val;
//    }
//}
class MyArray<T> {
    public T[] array = (T[])new Object[10];
    //public T[] array;
    public T getPos(int pos) {
        return this.array[pos];
    }
    public void setVal(int pos,T val) {
        this.array[pos] = val;
    }
}